from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-05 14:03:21.083985
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 05, Dec, 2021
Time: 14:03:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.3645
Nobs: 496.000 HQIC: -47.8281
Log likelihood: 5691.54 FPE: 1.25429e-21
AIC: -48.1278 Det(Omega_mle): 1.04805e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.381211 0.082024 4.648 0.000
L1.Burgenland 0.094520 0.044410 2.128 0.033
L1.Kärnten -0.116152 0.022780 -5.099 0.000
L1.Niederösterreich 0.166167 0.092118 1.804 0.071
L1.Oberösterreich 0.128482 0.093399 1.376 0.169
L1.Salzburg 0.281868 0.047638 5.917 0.000
L1.Steiermark 0.016104 0.061548 0.262 0.794
L1.Tirol 0.107543 0.049657 2.166 0.030
L1.Vorarlberg -0.084862 0.043747 -1.940 0.052
L1.Wien 0.032215 0.083611 0.385 0.700
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.023038 0.182082 0.127 0.899
L1.Burgenland -0.051662 0.098585 -0.524 0.600
L1.Kärnten 0.036543 0.050569 0.723 0.470
L1.Niederösterreich -0.223470 0.204489 -1.093 0.274
L1.Oberösterreich 0.478819 0.207332 2.309 0.021
L1.Salzburg 0.312226 0.105750 2.952 0.003
L1.Steiermark 0.099223 0.136629 0.726 0.468
L1.Tirol 0.308139 0.110232 2.795 0.005
L1.Vorarlberg 0.008368 0.097112 0.086 0.931
L1.Wien 0.019600 0.185605 0.106 0.916
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.230473 0.041738 5.522 0.000
L1.Burgenland 0.090634 0.022598 4.011 0.000
L1.Kärnten -0.004716 0.011592 -0.407 0.684
L1.Niederösterreich 0.219927 0.046874 4.692 0.000
L1.Oberösterreich 0.166299 0.047526 3.499 0.000
L1.Salzburg 0.035495 0.024241 1.464 0.143
L1.Steiermark 0.025182 0.031319 0.804 0.421
L1.Tirol 0.075335 0.025268 2.981 0.003
L1.Vorarlberg 0.056385 0.022261 2.533 0.011
L1.Wien 0.106729 0.042545 2.509 0.012
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166430 0.040617 4.098 0.000
L1.Burgenland 0.043116 0.021991 1.961 0.050
L1.Kärnten -0.012518 0.011280 -1.110 0.267
L1.Niederösterreich 0.147107 0.045616 3.225 0.001
L1.Oberösterreich 0.345900 0.046250 7.479 0.000
L1.Salzburg 0.099742 0.023590 4.228 0.000
L1.Steiermark 0.106733 0.030478 3.502 0.000
L1.Tirol 0.086238 0.024590 3.507 0.000
L1.Vorarlberg 0.054104 0.021663 2.498 0.013
L1.Wien -0.037106 0.041403 -0.896 0.370
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164504 0.078412 2.098 0.036
L1.Burgenland -0.041060 0.042455 -0.967 0.333
L1.Kärnten -0.036356 0.021777 -1.669 0.095
L1.Niederösterreich 0.125850 0.088061 1.429 0.153
L1.Oberösterreich 0.188484 0.089286 2.111 0.035
L1.Salzburg 0.254822 0.045540 5.596 0.000
L1.Steiermark 0.071978 0.058838 1.223 0.221
L1.Tirol 0.130358 0.047471 2.746 0.006
L1.Vorarlberg 0.105525 0.041821 2.523 0.012
L1.Wien 0.039391 0.079929 0.493 0.622
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.086811 0.062138 1.397 0.162
L1.Burgenland 0.014556 0.033643 0.433 0.665
L1.Kärnten 0.051359 0.017257 2.976 0.003
L1.Niederösterreich 0.175675 0.069785 2.517 0.012
L1.Oberösterreich 0.336603 0.070755 4.757 0.000
L1.Salzburg 0.049474 0.036089 1.371 0.170
L1.Steiermark -0.007073 0.046626 -0.152 0.879
L1.Tirol 0.123050 0.037618 3.271 0.001
L1.Vorarlberg 0.059115 0.033141 1.784 0.074
L1.Wien 0.112408 0.063340 1.775 0.076
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172625 0.075428 2.289 0.022
L1.Burgenland 0.011686 0.040839 0.286 0.775
L1.Kärnten -0.060949 0.020948 -2.909 0.004
L1.Niederösterreich -0.113578 0.084710 -1.341 0.180
L1.Oberösterreich 0.231548 0.085888 2.696 0.007
L1.Salzburg 0.037498 0.043807 0.856 0.392
L1.Steiermark 0.264621 0.056599 4.675 0.000
L1.Tirol 0.489269 0.045664 10.715 0.000
L1.Vorarlberg 0.071173 0.040229 1.769 0.077
L1.Wien -0.100874 0.076888 -1.312 0.190
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.138520 0.083365 1.662 0.097
L1.Burgenland -0.012844 0.045136 -0.285 0.776
L1.Kärnten 0.064187 0.023152 2.772 0.006
L1.Niederösterreich 0.170492 0.093624 1.821 0.069
L1.Oberösterreich -0.074173 0.094926 -0.781 0.435
L1.Salzburg 0.221624 0.048417 4.577 0.000
L1.Steiermark 0.135131 0.062555 2.160 0.031
L1.Tirol 0.050019 0.050469 0.991 0.322
L1.Vorarlberg 0.142561 0.044462 3.206 0.001
L1.Wien 0.168236 0.084978 1.980 0.048
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.457115 0.046039 9.929 0.000
L1.Burgenland -0.000760 0.024927 -0.030 0.976
L1.Kärnten -0.013200 0.012786 -1.032 0.302
L1.Niederösterreich 0.177314 0.051704 3.429 0.001
L1.Oberösterreich 0.267733 0.052423 5.107 0.000
L1.Salzburg 0.019132 0.026739 0.716 0.474
L1.Steiermark -0.014759 0.034546 -0.427 0.669
L1.Tirol 0.069415 0.027872 2.491 0.013
L1.Vorarlberg 0.056359 0.024554 2.295 0.022
L1.Wien -0.016577 0.046930 -0.353 0.724
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.026207 0.091081 0.154327 0.137977 0.063219 0.081712 0.015300 0.207406
Kärnten 0.026207 1.000000 -0.037383 0.127199 0.047628 0.072556 0.456515 -0.082160 0.093941
Niederösterreich 0.091081 -0.037383 1.000000 0.275898 0.096403 0.252066 0.050610 0.141243 0.243618
Oberösterreich 0.154327 0.127199 0.275898 1.000000 0.189311 0.283778 0.160978 0.124635 0.177609
Salzburg 0.137977 0.047628 0.096403 0.189311 1.000000 0.118212 0.060722 0.109572 0.062107
Steiermark 0.063219 0.072556 0.252066 0.283778 0.118212 1.000000 0.131107 0.087237 0.004123
Tirol 0.081712 0.456515 0.050610 0.160978 0.060722 0.131107 1.000000 0.063197 0.128206
Vorarlberg 0.015300 -0.082160 0.141243 0.124635 0.109572 0.087237 0.063197 1.000000 -0.011694
Wien 0.207406 0.093941 0.243618 0.177609 0.062107 0.004123 0.128206 -0.011694 1.000000